package com.net.shop.car.manager.api.volley.response.pay;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.net.shop.car.manager.api.model.PayType;
import com.net.shop.car.manager.api.volley.Response;
import com.net.shop.car.manager.utils.Constants;
import com.net.shop.car.manager.utils.LogUtils;
import com.net.shop.car.manager.utils.StringUtils;

public class GetPayTypeResponse extends Response {
	
	private long vb;
	private List<PayType> payTypes;

	public GetPayTypeResponse() {
		super(Constants.PAYTYPE);
	}
	
	/**
	 * @return the vb
	 */
	public long getVb() {
		return vb;
	}

	/**
	 * @return the payTypes
	 */
	public List<PayType> getPayTypes() {
		return payTypes;
	}

	@Override
	public String[] getContentTags() {
		return new String[]{"vb","pay_way"};
	}
	
	@Override
	public void parseContent(String content, int index) {
		if (index == 0) {
			vb = StringUtils.filterLongNull(content);
		} else {
			try {
				payTypes = new ArrayList<PayType>();
				JSONArray jsonArray = new JSONArray(content);
				for (int i = 0; i < jsonArray.length(); i++) {
					JSONObject jsonObject = jsonArray.getJSONObject(i);
					PayType payType = new PayType();
					payType.setDicName(StringUtils.filterIntegerNull(jsonObject.getString("DIC_NAME")));
					payType.setDicValue(StringUtils.filterNull(jsonObject.getString("DIC_VALUE")));
					payTypes.add(payType);
				}
			} catch (JSONException e) {
				LogUtils.e(e.getMessage());
			}
		}
	}

}
